<?php  

/**
* View
*/
class View
{
  protected static $_instance;
  public static function getInstance(){
    if(self::$_instance==null){
      self::$_instance= new View();
    }
    return self::$_instance;
  }
  
  protected $_engineClass = 'miho.yate.Yate';
  public function setEngineClass($value){
    $this->_engineClass = $value;
  }
  public function getEngineClass(){
    return $this->_engineClass;
  }
  
  protected $_engine;
  public function getEngine(){
    return $this->_engine;
  }
  
  protected $_mediators = array();
  
  protected $_useLayout = true;
  public function useLayout($value){
    $this->_useLayout = (bool)$value;
  }
  
  protected $_layout = 'layout';
  public function setLayout($layout){
    $this->_layout = $layout;
  }
  
  protected $_layoutPath = 'scripts/layout';
  public function setLayoutPath($value){
    $this->_layoutPath = $value;
  }
  
  protected $_scriptsPath = 'scripts';
  
  protected $_tempaltesHome = '/';
  public function setTemplatesHome($value){
    $this->_tempaltesHome = $value;
  }
  
  public function getTemplatesHome(){
    return $this->_tempaltesHome;
  }
  
  public function initialize(){
    import($this->_engineClass);
    $this->_engine = new Yate();
  }
  
  public function render($script, $vars){
    $this->_engine->setLayout($this->_tempaltesHome.'/'.$this->_layoutPath.'/'.$this->_layout);
    return $this->_engine->render($this->_tempaltesHome.'/'.$script, $vars);
  }
  
  public function renderPartial($partial,$params){
    return $this->_engine->renderPartial($partial,$params);
  }
  
  protected function __construct()
  {
   
  }
  
  public function registerMediator($mediator){
    $this->_mediators[$mediator->getName()] = $mediator;
  }
  
  public function retrieveMediator($name){
    if(!isset($this->_mediators[$name])) throw new Exception('Mediator '.$name.'not registered.');
    return $this->_mediators[$name];
  }
  
  public function plugin($name){
    return $this->_engine->plugin($name);
  }
}

?>